package com.myportfolio.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.UIObject;
import com.google.gwt.user.client.ui.Widget;

public class AhchorPanel extends Composite implements
		Refreshable<AnchorViewData> {

	@UiField
	protected Anchor anchor;

	@UiField
	protected DivElement divtohide;

	interface AhchorPanelUiBinder extends UiBinder<Widget, AhchorPanel> {
	}

	private static AhchorPanelUiBinder uiBinder = GWT
			.create(AhchorPanelUiBinder.class);

	public AhchorPanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public AhchorPanel(final AnchorViewData anchorViewData) {
		this();
		refresh(anchorViewData);
	}

	@UiHandler("anchor")
	public void onClick(final ClickEvent clickEvent) {
		if (UIObject.isVisible(divtohide)) {
			UIObject.setVisible(divtohide, false);
		} else {
			UIObject.setVisible(divtohide, true);
		}
	}

	@Override
	public void refresh(final AnchorViewData viewData) {

		anchor.setHTML(viewData.getHeader());
		divtohide.setInnerText(viewData.getContent());
	}

}
